<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="icon iconfont icon-jifen"></i> 征婚列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                用户昵称：
                <el-input v-model="userName" placeholder="请输入用户昵称" class="handle-input"></el-input>
                手机号码：
                <el-input v-model="mobile" type="number" placeholder="请输入手机号码" class="handle-input"></el-input>
                <el-button type="primary" icon="search" @click="search">查询</el-button>
            </div>
            <el-table :data="tableData" border style="width: 100%" >
                <el-table-column prop="id" label="ID" width="60" align="center">
                </el-table-column>
                <el-table-column prop="nick_name" label="用户昵称" width="200">
                </el-table-column>
                <el-table-column prop="mobile" label="用户联系方式" >
                </el-table-column>
                <el-table-column prop="create_time" label="发布时间" >
                </el-table-column>
                <el-table-column label="操作" width="120" align="center">
                    <template slot-scope="scope">
                        <el-button size="small" type="text" @click="handleSelect(scope.$index, scope.row)">查看</el-button>
                        <el-button size="small" type="text" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" v-show="totalPages>10">
                <el-pagination @current-change="handleCurrentChange" layout="prev, pager, next" :total="totalPages">
                </el-pagination>
            </div>
        </div>
        <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteRow">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>

    export default {
        name: 'marriage',
        data() {
            return {
                pageIndex:1,//当前页码
                pageSize:10,//每页10条
                totalPages:1,//默认的总条数
                userName:'',//查看 用户昵称
                mobile:'',//查询手机号码
                tableData:[],//表格数据
                delVisible:false, //是否显示查看详情弹出层
                idx:-1,//当前选中的下标
                idxId:-1 //当前选中的ID
            }
        },
        created() {
            this.getMarriageData();
        },
        //计算属性
        computed: {
            data() {
            }
        },
        methods: {
            //获取tabs数据
            getMarriageData (){
                const querystring = require('querystring');
                const param ={
                    nickName:this.userName,
                    mobile:this.mobile,
                    pageIndex:this.pageIndex,
                    pageSize:this.pageSize
                }
                this.$axios.post('/manage/seeking-wedding/query',querystring.stringify(param)).then(response=>{
                    //console.log(response);
                    if(response.data.code==200){
                        this.tableData = response.data.data.currData;//赋值 table 列表数据
                        this.totalPages = response.data.data.totalPages;//更新分页总条数
                    }else{
                        this.$notify.error({
                            title: '获取征婚信息列表失败',
                            duration:2000,
                            message: '失败原因：'+response.data.msg
                        });
                    }
                    
                }).catch(error=>{
                   console.log(error); 
                });
            },
            //查询
            search (){
               this.getMarriageData();
            },
            // 分页导航
            handleCurrentChange (val){
                console.log(val);
                // this.cur_page = val;
                // this.getMarriageData();
            },
            //查看
            handleSelect (index,row){
                if(row.id &&row.id>0){
                    this.$router.push({path:"/marriage/detail/"+row.id});
                }else{
                    this.$message.error('获取用户ID失败:'+id);
                }

            },
            //删除
            handleDelete (index, row){
                this.idx = index;//当前的选中的ID
                this.idxId = row.id;
                this.delVisible = true;//隐藏提示框
            },
            //确定删除
            deleteRow (){
                //console.log(this.idxId);
                if(this.idxId>0){
                    
                    const querystring = require('querystring');
                    const param ={
                        id:this.idxId
                    }
                    this.$axios.post('/manage/seeking-wedding/query',querystring.stringify(param)).then(response=>{
                        //console.log(response);
                        if(response.data.code==200){
                            this.tableData.splice(this.idx, 1);
                            this.$message.success('删除成功');
                            this.delVisible = false;
                        }else{
                            this.$notify.error({
                                title: '删除失败',
                                duration:2000,
                                message: '失败原因：'+response.data.msg
                            });
                        }
                        
                    }).catch(error=>{
                         console.log(error); 
                    });
                }else{
                    console.log("获取ID失败："+this.idx);
                }
            }
            
        }
    }

</script>
<style lang="stylus" scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 250px;
        display: inline-block;
        margin-right :30px;
    }
    .del-dialog-cnt{
        font-size: 16px;
        text-align: center
    }
</style>
